package com.warm.select.api.orm.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * json转换工具类
 *
 * @author warm
 */
public class JsonUtil {

    static final ObjectMapper mapper = new ObjectMapper();

    /**
     * json字符串转换为对象
     *
     * @param json
     * @param obj
     * @return
     */
    public static <T> T jsonToObject(String json, Class<T> obj) {
        if (json == null || json.isEmpty()) {
            return null;
        }
        try {
            return mapper.readValue(json, obj);
        } catch (Exception e) {
            throw new RuntimeException("json字符串转换为对象！" , e);
        }
    }


}